package cn.itcast.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<String,Date> {


    @Override
    public Date convert(String source) {

        SimpleDateFormat format=null;
        Date date =null;
        try {
            if(source.contains("-")){
                format= new SimpleDateFormat("yyyy-MM-dd");
            }else{
                format= new SimpleDateFormat("yyyy/MM/dd");
            }
            date=format.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date;
    }
}
